package com.srit.forecast.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.srit.core.bean.Page;
import com.srit.forecast.bean.SevenDays;
import com.srit.forecast.bean.SevenDaysPort;
import com.srit.forecast.dao.SevenDaysDao;

@Service
public class SevenDaysDaoImpl implements SevenDaysDao {

	@Autowired(required = true)
	private JdbcTemplate jdbcTemplate;

	@Override
	public int getMaxId() {
		String sql = "select max(ID) as maxId from TC_SEVENDAYS ";
		return jdbcTemplate.queryForInt(sql);
	}

	@Override
	public void save(SevenDays sevenDays) {
		String sql = "insert into TC_SEVENDAYS (ID,pubTime,reportTime,cityWeather,cityTemp,creator,collator) values(SEQ_TC_SEVENDAYS.nextval,?,?,?,?,?,?)";
		jdbcTemplate.update(
				sql,
				new Object[] { sevenDays.getPubTime(),
						sevenDays.getReportTime(), sevenDays.getCityWeather(),
						sevenDays.getCityTemp(), sevenDays.getCreator(),
						sevenDays.getCollator() });

	}

	@Override
	public void savePort(List<SevenDaysPort> portList) {
		String sql = "insert into TC_SEVENDAYSPORT (ID,PARENTID,AREAID,windDirect,windSpeed,windDirectTurn,windSpeedTurn) values(SEQ_TC_SEVENDAYSPORT.nextval,?,?,?,?,?,?)";
		for (SevenDaysPort sdPort : portList) {
			jdbcTemplate.update(
					sql,
					new Object[] { sdPort.getParentId(), sdPort.getAreaId(),
							sdPort.getWindDirect(), sdPort.getWindSpeed(),
							sdPort.getWindDirectTurn(),
							sdPort.getWindSpeedTurn() });
		}

	}

	@Override
	public void update(SevenDays t) {
		// TODO Auto-generated method stub

	}

	@Override
	public SevenDays getById(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(Integer id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void page(Page page) {
		// TODO Auto-generated method stub

	}

}
